#!/usr/bin/env node

const fs  = require('fs'),
      fileName = process.argv[2] || __filename,
      log = console.log,
      err = console.error;

//文件不存在打印错误信息
if(!fs.existsSync(fileName)){
  err('%s not exist!',fileName);
  process.exit(1);
}

//命令行参数不是文件名称时打印错误信息

if(!fs.statSync(fileName).isFile()){
  err('%s is not file!',fileName);
  process.exit(2);
}

let stm = fs.createReadStream(fileName);
stm.on('error',(e)=>{
  log(e.message);
});

stm.pipe(process.stdout); 
